package com.ruoyi.system.service.req;

import com.ruoyi.common.core.domain.entity.RestaurantCustomer;
import com.ruoyi.system.service.enums.CustomerType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * @Author: ruohao
 * @Date: 2023/8/27
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class NormalCustomerAddDTO {
    @NotBlank(message = "客户名称不能为空")
    private String customerName;

    @NotBlank(message = "客户区域不能为空")
    private String location;

    @NotBlank(message = "客户手机号不能为空")
    private String phone;

    @NotNull(message = "门牌号不能为空")
    private String houseNumber;

    private String extra;

    public static RestaurantCustomer convertToDO(NormalCustomerAddDTO normalCustomerAddDTO) {
        if (normalCustomerAddDTO == null) {
            return null;
        }
        RestaurantCustomer restaurantCustomer = new RestaurantCustomer();
        restaurantCustomer.setCustomerId(normalCustomerAddDTO.getPhone());
        restaurantCustomer.setCustomerName(normalCustomerAddDTO.getCustomerName());
        restaurantCustomer.setLocation(normalCustomerAddDTO.getLocation());
        restaurantCustomer.setType(CustomerType.NORMAL.getCode());
        restaurantCustomer.setPhone(normalCustomerAddDTO.getPhone());
        restaurantCustomer.setHouseNumber(normalCustomerAddDTO.getHouseNumber());
        restaurantCustomer.setExtra(normalCustomerAddDTO.getExtra());
        restaurantCustomer.setBalance(new BigDecimal(0));
        return restaurantCustomer;
    }
}
